package com.strato.saas.merchant.v1_0_0.jdbc.store;

import java.util.HashMap;
import java.util.Map;

import com.strato.jdbc.datasource.v1_0_0.DataSourceFactory;
import com.strato.orm.mybatis.v1_0_0.factory.MapperFactory;
import com.strato.saas.merchant.v1_0_0.MerchantStore;
import com.strato.saas.merchant.v1_0_0.jdbc.dao.mapper.MerchantInfoMapper;
import com.strato.saas.merchant.v1_0_0.jdbc.model.MerchantInfo;

public class JdbcMerchantStore implements MerchantStore {

	private MerchantInfoMapper merchantInfoMapper;
	
	public MerchantInfoMapper getMerchantInfoMapper() {
		if(merchantInfoMapper==null){
			merchantInfoMapper=MapperFactory.getMapper(MerchantInfoMapper.class, DataSourceFactory.COMMON_DATASOURCE);
		}
		return merchantInfoMapper;
	}

	@Override
	public Object load(String merchantId) {
		MerchantInfo merchant = getMerchantInfoMapper().selectByPrimaryKey(merchantId);
		if(merchant==null){
			throw new NullPointerException("Unknown merchant:"+merchantId);
		}
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("conn_url", merchant.getConnUrl());
		map.put("conn_usr", merchant.getConnUsr());
		map.put("conn_pwd", merchant.getConnPwd());
		map.put("conn_minsize", merchant.getConnMinsize());
		map.put("conn_initsize", merchant.getConnInitsize());
		map.put("conn_maxsize", merchant.getConnMaxsize());
		return map;
	}

}
